package cn.gbase.verify.controller;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.logging.log4j.Log4jImpl;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import cn.gbase.verify.entity.Identity;
import cn.gbase.verify.service.IdentityMapper;
import cn.gbase.verify.service.IdentityService;
import verified.Test;

@EnableAutoConfiguration
@RestController
@RequestMapping("/identity")
public class IdentityController {
	private static Logger logger = Logger.getLogger(IdentityController.class);  
    @Autowired
	private IdentityService identityService;  
	@Autowired
	private JdbcTemplate jdbcTemplate; 

 	/*@RequestMapping("/nutz/{dn}")
	public Identity view(@PathVariable("dn") String dn) {
		Identity identity = new Identity();
		identity = identityService.get(dn);
		return identity;
	}  
*/
 	@RequestMapping("/SpJDBC/{dn}")
	public Identity getDbType(@PathVariable("dn") String dn) {
		final Identity identity = new Identity();  
		jdbcTemplate.query("SELECT DN,MASK,TIMESTAMP FROM TBL_IDENTITY WHERE DN = ?",  
                new Object[] {dn},  
                new RowCallbackHandler() {  
                    public void processRow(ResultSet rs) throws SQLException {  
                    	identity.setDn(rs.getString("dn"));  
                    	identity.setMask(rs.getString("mask")); 
                    	identity.setTimestamp(rs.getLong("timestamp")); 
                    }  
                });  
		return identity;
	} 
	@RequestMapping("/mybaties/{dn}")
	public Identity getDbTypeMybaties(@PathVariable("dn") String dn) {
		Identity identity = new Identity();  
		identity = identityService.get1(dn);
		return identity;
	} 
	@ResponseBody
	@RequestMapping("/get")
	public Identity getDb(Identity identity) {
        logger.info("This is info message.");  
		identity = identityService.get1(identity.getDn());
		return identity;
	} 
}
